package com.luna.servlets;

import com.luna.service.UserService;
import com.luna.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(
    name = "SwitchRestricted",
    urlPatterns = "/SwitchRestricted"
)
public class SwitchRestricted extends HttpServlet {

    public SwitchRestricted() {}

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        int id = Integer.parseInt(req.getParameter("uid"));
        int state = Integer.parseInt(req.getParameter("state"));
        UserService userService = new UserServiceImpl();
        if (userService.restricted(id, state)) {
            String json = "{\n" +
                    "\t\"res\": true,\n" +
                    "}";
            resp.getWriter().print(json);
        } else {
            String json = "{\n" +
                    "\t\"res\": false,\n" +
                    "}";
            resp.getWriter().print(json);
        }
    }
}
